package com.terrynoya.fight.stateMachine.triggers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.emuns.Operator;
	import com.terrynoya.fight.emuns.PhysicsEnum;
	import com.terrynoya.fight.evaluation.Node;
	import com.terrynoya.fight.evaluation.ParseState;

	public class Physics
	{
		public function Physics()
		{
			
		}
		
		public static function eval(data:Object,node:Node):*
		{
			var chara:Character = data as Character;	
			if(chara == null)
			{
				return PhysicsEnum.NONE;
			}
			return chara.physics;
		}
		
		public static function parse(state:ParseState):Node
		{
			var oper:int = state.currentOperator;
			if(oper != Operator.Equals && oper != Operator.NotEquals)
			{
				return null;
			}
			state.tokenIndex++;
			
			var text:String = state.currentToken.text;
			var stateType:int = getStateType(text);
			if(stateType == PhysicsEnum.Unchanged || stateType == PhysicsEnum.NONE)
			{
				return null;
			}
			state.tokenIndex++;
			
			state.baseNode.arguments.push(oper);
			state.baseNode.arguments.push(stateType);
			
			return state.baseNode;
		}
		
		private static function getStateType(text:String):int
		{
			var rlt:int = PhysicsEnum.NONE;
			switch(text.toLocaleLowerCase())
			{
				case "s":
				{
					rlt = PhysicsEnum.Standing;
					break;
				}
				case "a":
				{
					rlt = PhysicsEnum.Airborne;
					break;
				}
				case "c":
				{
					rlt = PhysicsEnum.Crouching;
					break;
				}
				case "u":
				{
					rlt = PhysicsEnum.Unchanged;
					break;
				}
			}	
			return rlt;
		}
	}
}